﻿using System;
using System.Collections.Generic;
using System.IO;

class SortListOfStringsToAnotherFile
{
    static void Main()
    {
        //Exercise 6.
        //Write a program that reads a text file containing a list of strings, sorts them and saves them to another text file. 
        //Example:
        //Ivan			George
        //Peter		->	Ivan
        //Maria			Maria
        //George		Peter

        StreamReader reader = new StreamReader(@"C:\Users\Toni\Desktop\Test File String.txt");
        StreamWriter writer = new StreamWriter(@"C:\Users\Toni\Desktop\Test String Result.txt");

        List<string> words = new List<string>();

        using (reader)
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                words.Add(line.Trim());     // removes any leading and trailing characters like white-spaces
                line = reader.ReadLine();
            }
        }

        words.Sort();       //sorts all the elements in the List-array

        using (writer)      //writes the sorted elements on a separate line in a new text file
        {
            foreach (string word in words)
            {
                writer.WriteLine(word);
            }
        }

    }
}

